package org.wbd.pklib.web.beans;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.wbd.pklib.db.logic.LogicRespond;
import org.wbd.pklib.db.logic.UserLogic;

public class RegisterUserBean {
	private String name;
	private String surname;
	private String login;
	private String password;
	private String email;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getSurname() {
		return surname;
	}
	public void setSurname(String surname) {
		this.surname = surname;
	}
	public String getLogin() {
		return login;
	}
	public void setLogin(String login) {
		this.login = login;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	
	public String register(){
		LogicRespond respond= UserLogic.getInstance().register(name, surname, login, password, email);
		if(respond.isSuccesful()){
			FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true);
			FacesMessage message= new FacesMessage("Zarejestrowano!");
			FacesContext.getCurrentInstance().addMessage(null, message);
			
		}
		else{
			FacesMessage message= new FacesMessage("Nie udało sie zarejestrować!");
			FacesContext.getCurrentInstance().addMessage(null, message);
		}
		
		return "MyPage.xhtml?faces-redirect=true";
	}
	
	
}
